<template>
  <div>
    <div class="kylin-form configure-confirm-table">
      <ky-table
        :getData="getReport"
        :search_criteria="search_criteria"
        :search_data="search_data"
        :appendToBody="true"
        :modalTable="true"
        ref="table"
      >
        <template v-slot:table>
          <el-table-column prop="ip" label="IP"> </el-table-column>
          <el-table-column prop="type" :label="$t('configure.configure_type')">
          </el-table-column>
          <el-table-column
            prop="config"
            :label="$t('configure.configure_item')"
          >
          </el-table-column>
          <el-table-column
            prop="baseline"
            :label="$t('configure.original_value')"
          >
          </el-table-column>
          <el-table-column prop="target" :label="$t('configure.target_value')">
          </el-table-column>
        </template>
      </ky-table>
    </div>
    <div slot="footer" class="dialog-footer">
      <el-button @click="handlePrevios">{{ $t("previous_step") }}</el-button>
      <el-button class="kylin-button" @click="handleConfirm">{{
        $t("configure.confirm_issue")
      }}</el-button>
    </div>
  </div>
</template>

<script>
import kyTable from "@/components/KyTable";
import {
  getReport,
  issueGroupByHost,
  issueGroupByBatch,
} from "@/api/configure_group";
export default {
  props: {
    id: {
      type: Number,
    },
    row_id: {
      type: Number,
    },
    batch_id: {
      type: Number,
    },
  },
  components: {
    kyTable,
  },
  data() {
    return {
      loading: false,
      tag: "all",
      search_criteria: {
        id: this.id,
        configGroupId: this.row_id,
      },
      search_data: {
        ip: {
          name: "IP",
          type: "text",
        },
        type: {
          name: "configure.configure_type",
          type: "text",
        },
        config: {
          name: "configure.configure_item",
          type: "text",
        },
        baseline: {
          name: "configure.original_value",
          type: "text",
        },
        target: {
          name: "configure.target_value",
          type: "text",
        },
      },
    };
  },
  methods: {
    getReport,
    handlePrevios() {
      this.$emit("click", "system");
    },
    handleConfirm() {
      if (this.batch_id) {
        issueGroupByBatch({
          id: this.id,
          groupIds: [this.row_id],
          batchId: this.batch_id,
        }).then((res) => {
          if (res.data.code === "0") {
            this.$message({
              type: "success",
              message: res.data.message,
            });
            this.$router.push({
              name: "log_detail",
              params: { id: res.data.data.parentId },
            });
            this.$emit("click", "success");
          } else {
            this.$message({
              type: "error",
              message: res.data.message,
            });
          }
        });
      } else {
        issueGroupByHost({
          id: this.id,
          groupIds: [this.row_id],
        }).then((res) => {
          if (res.data.code === "0") {
            this.$message({
              type: "success",
              message: res.data.message,
            });
            this.$emit("click", "success");
            this.$router.push({
              name: "log_detail",
              params: { id: res.data.data.parentId },
            });
          } else {
            this.$message({
              type: "error",
              message: res.data.message,
            });
          }
        });
      }
      this.$emit("click", "report");
    },
  },
};
</script>

<style rel="stylesheet/scss" lang="scss" scoped>
.configure-confirm-table {
  max-height: 600px;
  overflow: auto;
}
.kylin-compare-radio {
  margin-right: 10px;
}
</style>